#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"
void STinit(ST* ptr)
{
	assert(ptr);
	ptr->_size = 0;
	ptr->_capacity = 4;
	ptr->_ptr = (StackType*)malloc(sizeof(StackType) * ptr->_capacity);
	memset(ptr->_ptr, 0,ptr->_capacity * sizeof(StackType));
}
void judge(ST* ptr)
{
	if (ptr->_size == ptr->_capacity)
	{
		ptr->_capacity *= 2;
		StackType* tem = (StackType*)realloc(ptr->_ptr, ptr->_capacity * sizeof(StackType));
		if (tem)
		{
			ptr->_ptr = tem;
			return;
		}
		perror("realloc:");
	}
}
void STpush(ST* ptr, StackType val)
{
	judge(ptr);
	ptr->_ptr[ptr->_size++] = val;

}
bool STempty(ST* ptr)
{
	return !ptr->_size;
}
void STdestroy(ST* ptr)
{
	free(ptr->_ptr);
	ptr->_ptr = nullptr;
	free(ptr);
	ptr = nullptr;
}
StackType STpop(ST* ptr)
{
	ptr->_size--;
	return ptr->_ptr[ptr->_size + 1];
}
StackType STtop(ST* ptr)
{
	return ptr->_ptr[ptr->_size - 1];
}
ST* STcreat()
{
	ST* tem = (ST*)malloc(sizeof(ST));
	if (tem)
	{
		return tem;
	}
	return nullptr;
}